<template>
  <div class="box-wrap">
    <div class="tabtab">
      <el-tabs
        v-model="searchData.role_id"
        @tab-click="handleTabClick"
        type="card"
      >
        <el-tab-pane label="代理商管理" name="3"> </el-tab-pane>
        <el-tab-pane label="渠道主管理" name="4"> </el-tab-pane>
      </el-tabs>
    </div>
    <section class="box-operation">
      <div class="box-search">
        <div class="form-group-enquire">
          <Input
            v-model.trim="searchData.account"
            placeholder="账户"
            clearable
            @on-enter="onSearchGetList()"
          ></Input>
        </div>
        <div class="form-group-enquire">
          <el-select
            v-model="searchData.leader_id"
            placeholder="上级"
            clearable
            filterable
          >
            <el-option
              :value="row.id"
              v-for="row in leaderlist"
              :label="row.account"
              :key="row.id"
              >{{ row.account }}</el-option
            >
          </el-select>
        </div>
        <!-- <div class='form-group-enquire' v-if="UserInfo.role!='代理商'">
          <el-select v-model="searchData.role_id" placeholder="角色" clearable filterable>
            <el-option :value= row.id v-for="row in rollist" :label="row.name" :key= row.id >{{row.name}}</el-option>
          </el-select>
        </div> -->
        <div class="form-group-enquire">
          <el-select
            v-model="searchData.tag"
            placeholder="客户属性"
            clearable
            filterable
            collapse-tags
          >
            <el-option
              :value="row.id"
              v-for="row in this.format.tag.labelValue"
              :label="row.name"
              :key="row.id"
              >{{ row.name }}</el-option
            >
          </el-select>
        </div>
        <div class="form-group-enquire">
          <el-select
            v-model="searchData.status"
            placeholder="状态"
            clearable
            filterable
          >
            <el-option
              :value="row.id"
              v-for="row in statuslist"
              :label="row.name"
              :key="row.id"
              >{{ row.name }}</el-option
            >
          </el-select>
        </div>
        <div class="form-group-enquire-date">
          <DatePicker
            type="daterange"
            placeholder="注册时间"
            :editable="false"
            v-model="searchDate"
            @on-change="changeDate"
            @on-clear="initDate"
          ></DatePicker>
        </div>
        <div class="form-group-img" @click="onSearchGetList()">
          <img src="../../assets/images/peach-svg/Frame 23.svg" />
        </div>
        <div class="form-group-addimg" @click="editInfo({}, 1)">
          <img src="../../assets/images/peach-svg/add.svg" />
        </div>
        <!-- <div class="form-group-addimg2" @click="downloadFile(1, {})">
          <img src="../../assets/images/peach-svg/export.svg" />
        </div> -->
        <!-- <div class='form-group-addimg' @click='PiliangLookAPI()'><img src="../../assets/images/peach-svg/mach.svg"></div> -->
      </div>
    </section>
    <template>
      <Modal v-model="modal2" title="Api查看">
        <Input type="textarea" v-model="Content" />
        <!-- <p>{{Content}}</p> -->
        <Button @click="handleCopy">复制</Button>
      </Modal>
    </template>
    <!-- 单个api修改 -->
    <template>
      <el-dialog
        :visible.sync="treeshow"
        class="treetree"
        :modal="true"
        title="权限修改"
      >
        <el-input placeholder="输入关键字进行过滤" v-model="filterText">
        </el-input>
        <el-tree
          :data="menuList"
          show-checkbox
          check-on-click-node
          node-key="id"
          :filter-node-method="filterNode"
          :default-expanded-keys="[]"
          ref="tree"
        >
        </el-tree>

        <div class="buttons">
          <el-button @click="getCheckedNodes">取消</el-button>
          <el-button @click="getCheckedKeys">确定</el-button>
          <el-button @click="resetChecked">清空</el-button>
        </div>
      </el-dialog>
    </template>
    <!-- 批量api修改 -->
    <template>
      <el-dialog
        :visible.sync="treeshow2"
        class="treetree"
        :modal="true"
        title="权限修改"
      >
        <el-input placeholder="输入关键字进行过滤" v-model="filterText">
        </el-input>
        <el-tree
          :data="menuList"
          show-checkbox
          check-on-click-node
          node-key="id"
          :filter-node-method="filterNode"
          :default-expanded-keys="[]"
          ref="tree"
        >
        </el-tree>

        <div class="buttons">
          <el-button @click="getCheckedNodes">取消</el-button>
          <el-button @click="PlgetCheckedKeys">确定</el-button>
          <el-button @click="resetChecked">清空</el-button>
        </div>
      </el-dialog>
    </template>
    <LibVxeTable
      class="staticData"
      :stripe="stripe"
      border="none"
      :tableColumns="tableColumns"
      :tableData="list"
      :slotHeader="slotHeader"
      :PageObj="{
        total: totalCnt,
        currentPage: searchData.page_index,
        pageSize: searchData.page_size,
      }"
      @onPageChange="onChangePageSize"
      @onSelectChange="onCheckChange"
      resizable
    ></LibVxeTable>
  </div>
</template>
<script>
import { mapGetters } from "vuex";
import utils from "../../commons/utils";
import { commonMixin } from "../../components/ViewInitMixin"; //每一个文件都要包含这个
import { TimePicker } from "iview";
import SearchUser from "../searchUser";
import bus from "../../commons/EventBus";
import Request from "../../commons/Request";

export default {
  name: "addUserDetailView", //!!这块一定要注意，每一个文件都根据资源path来命名
  components: { TimePicker, SearchUser },
  mixins: [commonMixin],
  watch: {
    filterText(val) {
      this.$refs.tree.filter(val);
    },
    treeshow(val) {
      if (val == false) {
        this.$refs.tree.setCheckedKeys([]);
      }
    },
    treeshow2(val) {
      if (val == false) {
        this.$refs.tree.setCheckedKeys([]);
      }
    },
  },
  data() {
    const validateaccount = (rule, value, callback) => {
      // let s=/^[^\u4e00-\u9fa5]{4,20}$/ //不包含中文4-20位字符 s.test(value)==""
      if (value == "") {
        callback(new Error("账号不能为空"));
      } else if (value.length < 4 || value.length > 20) {
        callback(new Error("账号名称长度在4-20位字符之内"));
      } else {
        callback();
      }
    };
    const validatepasswd = (rule, value, callback) => {
      var s = /^(?![\u4e00-\u9fa5])(?:(?=.*[a-zA-Z])(?=.*\d|.*[@#￥！……$%^&*()_+!~-])|(?=.*\d)(?=.*[a-zA-Z~!@￥！……#$%^&*()_+])|(?=.*[@#￥！……$%^&*()_+~!~-])(?=.*[a-zA-Z\d]))[a-zA-Z\d@￥！……#$%^&*()_+!~-]{8,20}$/;
      if (value == "") {
        callback(new Error("密码不能为空"));
      } else if (s.test(value) == "") {
        callback(
          new Error(
            "密码长度在8-20位字符之内，包含字母、数字、特殊符号其中两种"
          )
        );
      } else {
        callback();
      }
    };
    const validateRole = (rule, value, callback) => {
      if (value == "") {
        callback(new Error("用户角色必须选择"));
      } else {
        callback();
      }
    };
    const validateLeader = (rule, value, callback) => {
      if (value == "") {
        callback(new Error("上级角色必须选择"));
      } else {
        callback();
      }
    };
    return {
      filterText: "",
      stripe: false,
      statuslist: [
        { id: 1, name: "正常" },
        { id: 2, name: "冻结" },
      ],
      pilianglist: [],
      Content: "",
      modal2: false,
      modal: false,
      searchDate: "",
      treeshow: false,
      treeshow2: false,
      menuList: [],
      rows: [],
      pList: [],
      pList2: [],
      priceId: "",
      searchTime: [
        utils.dateFormat(0, "HH") + "00",
        utils.dateFormat(0, "HH") + "00",
      ],
      searchData: {
        account: "",
        page_index: 1,
        page_size: 30,
        create_at: "",
        status: "",
        role_id: "3",
        leader_id: "",
        tag: "",
      },
      tag: "",
      versionsList: [
        { Id: -1, Name: "全部版本" },
        { Id: 1, Name: "v1" },
        { Id: 2, Name: "v2" },
      ],
      mnoList: {},
      provinceList: {},
      list: [],
      // nameas:this.searchData.role_id==='3'?"筛源方案":"业务方案",
      totalCnt: 0,
      info: {},
      channelList: [],
      cityList: [],
      cityInfo: [-1],
      partnerList: [],
      ChannelList: [],
      QdsPartnerList: [],
      QdsPartnerObj: {},
      BusinessList: [],
      BusinessObj: {},
      cityObj: {},
      brandObj: {},
      brandObjCh: {},
      roles: [],
      leaders: [],
      roleList: {},
      rollist: [],
      leaderlist: [],
      eid: "",
      selectRows: [],
      format: {
        account: {
          labelName: "账号",
          labelType: "text",
          placeholder: "请输入账号",
        },
        passwd: {
          labelName: "密码",
          labelType: "text",
          placeholder: "请输入密码",
        },
        role_id: {
          labelName: "用户角色",
          labelType: "select",
          labelValue: [],
          placeholder: "请选择角色",
          labelChange: "role_id",
        },
        leader_id: {
          labelName: "上级",
          labelType: "select",
          labelValue: [],
          placeholder: "请选择上级",
          labelHide: false,
        },
        sieve_source_config_id: {
          labelName: "筛号源",
          labelType: "select",
          labelValue: [],
          placeholder: "请选择筛号源",
        },
        tag: {
          labelName: "账号属性",
          labelType: "select",
          placeholder: "请选择账号属性",
          labelValue: [
            { id: "测试", name: "测试" },
            { id: "客户", name: "客户" },
            { id: "内部", name: "内部" },
            { id: "API", name: "API" },
          ],
        },
      },
      ruleValidate: {
        role_id: [{ required: true, validator: validateRole, trigger: "blur" }],
        account: [
          { required: true, validator: validateaccount, trigger: "blur" },
        ],
        passwd: [
          { required: true, validator: validatepasswd, trigger: "blur" },
        ],
      },
      dateOptions: {
        disabledDate(date) {
          return date && date.valueOf() > Date.now();
        },
      },
    };
  },
  computed: {
    ...mapGetters(["UserInfo"]),
    tableColumns() {
      let table = [];
      table.push(
        {
          field: "Id",
          type: "checkbox",
          align: "center",
          width: 50,
        },
        {
          title: "序号",
          field: "ids",
          align: "center",
          slots: {
            default: ({ rowIndex, row }, h) => {
              return [
                h(
                  "div",
                  this.searchData.page_size * (this.searchData.page_index - 1) +
                    (rowIndex + 1)
                ),
              ];
            },
          },
        },
        {
          title: "用户ID",
          field: "id",
          align: "center",
        },
        {
          title: "账号",
          field: "account",
          align: "center",
        },
        {
          title: "账号属性",
          field: "tag",
          align: "center",
          // slots: {
          //   default: ({ row }, h) => {
          //     return [
          //       h(
          //         "div",
          //         row.tag === "1"
          //           ? "测试"
          //           : row.tag === "2"
          //           ? "客户"
          //           : row.tag === "3"
          //           ? "内部"
          //           : row.tag === "4"
          //           ? "API"
          //           : "其他"
          //       ),
          //     ];
          //   },
          // },
        },
        {
          title: "剩余充值",
          field: "recharge_points",
          align: "center",
          slots: {
            default: ({ row }, h) => {
              if (row.recharge_points == 0) {
                return [h("div", "-")];
              } else return [h("div", row.recharge_points / 10000)];
            },
          },
        },
        {
          title: "剩余赠送",
          field: "bonus_points",
          align: "center",
          slots: {
            default: ({ row }, h) => {
              if (row.bonus_points == 0) {
                return [h("div", "-")];
              } else return [h("div", row.bonus_points / 10000)];
            },
          },
        },
        {
          title: "充值消耗",
          field: "points_consume_account",
          align: "center",
          slots: {
            default: ({ row }, h) => {
              if (row.points_consume_account == 0) {
                return [h("div", "-")];
              } else return [h("div", row.points_consume_account / 10000)];
            },
          },
        },
        {
          title: "赠送消耗",
          field: "points_consume_gift",
          align: "center",
          slots: {
            default: ({ row }, h) => {
              if (row.points_consume_gift == 0) {
                return [h("div", "-")];
              } else return [h("div", row.points_consume_gift / 10000)];
            },
          },
        }
      );
      if (this.searchData.role_id === "3") {
        table.push({
          title: "筛源方案",
          field: "business_price_name",
          align: "center",
        });
      } else {
        table.push(
          {
            title: "业务方案",
            field: "business_price_name",
            align: "center",
          },
          {
            title: "15天内登录",
            field: "last_login",
            align: "center",
            slots: {
              default: ({ row }, h) => {
                let times = row.last_login + 86400 * 15 > Date.parse(new Date()) / 1000
                if (times) {
                  return [h("div", "是")];
                } else return [h("div", "否")];
              },
            },
          },
          {
            title: "15天内充值",
            field: "last_recharge",
            align: "center",
            slots: {
              default: ({ row }, h) => {
                let times = row.last_recharge + 86400 * 15 > Date.parse(new Date()) / 1000
                if (times) {
                  return [h("div", "是")];
                } else return [h("div", "否")];
              },
            },
          },
          {
            title: "15天内消耗",
            field: "last_consume",
            align: "center",
            slots: {
              default: ({ row }, h) => {
                let times = row.last_consume + 86400 * 15 > Date.parse(new Date()) / 1000
                if (times) {
                  return [h("div", "是")];
                } else return [h("div", "否")];
              },
            },
          }
        );
      }
      table.push(
        {
          title: "角色",
          field: "role_name",
          align: "center",
        },
        {
          title: "上级",
          field: "leader_name",
          align: "center",
        },
        {
          title: "状态",
          field: "status",
          align: "center",
          slots: {
            default: ({ row }, h) => {
              if (this.UserInfo.role == "代理商") {
                return [h("div", row.status == 1 ? "正常" : "冻结")];
              } else {
                let disabled = false;
                if (this.Perm.add) {
                  disabled = false;
                }
                return [
                  h(
                    "iSwitch",
                    {
                      props: {
                        value: (1 & row.status) == 1 ? true : false,
                        disabled: disabled,
                        size: "large",
                      },
                      on: {
                        "on-change": (value) => {
                          let info = { id: row.id };
                          value == true
                            ? (this.handleType = 4)
                            : (this.handleType = 5);
                          this.updateInfo(info);
                        },
                      },
                    },
                    [
                      h("span", {
                        slot: "open",
                        domProps: {
                          innerHTML: "正常",
                        },
                      }),
                      h("span", {
                        slot: "close",
                        domProps: {
                          innerHTML: "冻结",
                        },
                      }),
                    ]
                  ),
                ];
              }
            },
          },
        },
        {
          title: "注册时间",
          field: "create_at",
          align: "center",
          width: 150,
          slots: {
            default: ({ row }, h) => {
              if (row.create_at == 0) {
                return [h("div", "-")];
              } else
                return [
                  h(
                    "div",
                    utils.dateFormat(row.create_at, "yyyy-MM-dd HH:mm:ss")
                  ),
                ];
            },
          },
        },
        {
          title: "操作",
          field: "action",
          width: 170,
          align: "center",
          slots: {
            default: ({ row }, h) => {
              return this.$AutoFun(() => {
                let hButton = [];
                hButton.push(
                  h("div", {
                    class: "looklook",
                    on: {
                      click: () => {
                        this.lookInfo(row);
                      },
                    },
                  })
                );
                hButton.push(
                  h("div", {
                    props: { type: "primary", size: "small" },
                    style: { marginRight: "5px" },
                    class: "two",
                    on: {
                      click: () => {
                        this.editInfo(row, 2);
                      },
                    },
                  })
                );
                hButton.push(
                  h("div", {
                    props: { type: "danger", size: "small" },
                    style: { marginRight: "5px" },
                    class: "three",
                    on: {
                      click: () => {
                        this.sureDel(row, -1);
                      },
                    },
                  })
                );
                if (row.role_name == "渠道主") {
                  hButton.push(
                    h("Dropdown", [
                      h("div", {
                        props: { type: "danger", size: "small" },
                        style: { marginRight: "5px" },
                        class: "one",
                      }),
                      h(
                        "DropdownMenu",
                        {
                          slot: "list",
                        },
                        [
                          h(
                            "DropdownItem",
                            {
                              nativeOn: {
                                click: (name) => {
                                  this.editInfo(row, 3);
                                },
                              },
                            },
                            "重置密码"
                          ),
                          // h('DropdownItem',{
                          //   nativeOn:{
                          //     click:(name)=>{
                          //       this.trees(row);
                          //     }
                          //   }
                          // },'更换筛号源'),
                          h(
                            "DropdownItem",
                            {
                              nativeOn: {
                                click: (name) => {
                                  this.LookAPI(row.id);
                                },
                              },
                            },
                            "API查看"
                          ),
                        ]
                      ),
                    ])
                  );
                } else {
                  hButton.push(
                    h("Dropdown", [
                      h("div", {
                        props: { type: "danger", size: "small" },
                        style: { marginRight: "5px" },
                        class: "one",
                      }),
                      h(
                        "DropdownMenu",
                        {
                          slot: "list",
                        },
                        [
                          h(
                            "DropdownItem",
                            {
                              nativeOn: {
                                click: (name) => {
                                  this.editInfo(row, 3);
                                },
                              },
                            },
                            "重置密码"
                          ),
                        ]
                      ),
                    ])
                  );
                }
                return hButton;
              });
            },
          },
        }
      );
      return table;
    },
  },
  methods: {
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
    async initView(isMounted) {
      if (isMounted) {
        await this.getList();
        await this.initSearchData();
      }
    },
    handleTabClick(tab) {
      this.searchData.role_id = tab.name;
      this.getList();
    },
    //多选框数组
    onCheckChange(rows) {
      this.selectRows = [];
      this.selectRows = rows;
    },
    //api单个修改对应
    async LookAPI(row) {
      this.modal2 = true;
      let apis = await this.RequestPost("getAPIToken_item", { id: row }); //api
      this.Content = apis.data;
    },
    //批量api修改
    async PiliangLookAPI() {
      this.treeshow2 = true;
    },
    //批量添加权限方法
    async PlgetCheckedKeys() {
      let new_ids = "";
      if (
        (this.selectRows.checked == true &&
          this.selectRows.records.length >= 1) ||
        (this.selectRows.checked == false &&
          this.selectRows.records.length >= 1)
      ) {
        //导出值用id|id形式拼接
        this.selectRows.records.forEach((item) => {
          new_ids += "|" + item.id;
        });
        if (new_ids != "") {
          new_ids = new_ids.substring(1);
        }
      }
      this.treeshow2 = false;
      let keylist = this.$refs.tree.getCheckedKeys(true); //获取取到的id值
      let biz_ids = keylist.join("|");
      if (keylist.length === 0) {
        biz_ids = "empty";
      }
      let res = await this.RequestPost("edit_item", {
        id: new_ids,
        business_type_ids: biz_ids,
      });
      utils.showTip("筛源修改成功1！");
      if (res.code === 0) {
        utils.showTip("筛源修改成功！");
      }
    },
    handleCopy() {
      const oInput = document.createElement("input");
      oInput.value = this.Content;
      document.body.appendChild(oInput);
      oInput.select();
      document.execCommand("Copy");
      this.$message({
        message: "复制成功",
        type: "success",
      });
      oInput.remove();
    },
    //查看
    async lookInfo(row) {
      let info = {};
      info = {
        id: row.id,
        account: row.account,
        role_id: row.role_id,
        leader_id: row.leader_id,
        tag: row.tag,
      };
      let title = "查看用户配置";
      this.handleType = 8;
      this.formPopIndex = await utils.showFormPage(
        { title: title, el: this.$parent.$el, width: 700, cancelBtnStatus: 0 },
        info,
        this.format,
        this.ruleValidate,
        this.updateInfo
      );
    },
    async initSearchData() {
      let roles = await this.RequestPost("queryRoles_list"); //角色
      let roles2 = await this.RequestPost("queryRoles_list", {
        submit_type: 1,
      }); //不要管理员
      let leaders = await this.RequestPost("queryLeaders_list", {
        submit_type: 1,
      });
      let res2 = await Request.post("customer/sieveConfig", "query_list"); //筛料源接口
      if (res2.code == 0 && res2.data.list != null) {
        res2.data.list.forEach((res2) => {
          this.pilianglist.push({ id: res2.id, name: res2.name });
        });
        this.format.sieve_source_config_id.labelValue = this.pilianglist;
      }
      //角色
      if (roles.data != null) {
        roles.data.forEach((item) => {
          this.rollist.push(item);
          this.$set(this.roleList, item.id, item.name);
        });
      }
      //角色
      if (roles2.data != null) {
        roles2.data.forEach((item) => {
          this.format.role_id.labelValue.push({ id: item.id, name: item.name });
        });
      }
      //上级
      if (leaders.code == 0) {
        if (leaders.data != null) {
          leaders.data.forEach((item) => {
            this.leaderlist.push(item);
            this.format.leader_id.labelValue.push({
              id: item.id,
              name: item.account,
            });
          });
        }
      }
      let res = await this.RequestPost("querySieveConfig_item"); //api
      this.menuList = [];
      if (res.code == 0) {
        res.data.forEach((item) => {
          let info = this.loopResourceData(item);
          this.menuList.push(info);
        });
      }
    },
    loopResourceData(item) {
      let info = {
        id: item.business_type_id,
        label: item.Label,
        children: [],
        ParentMod: item.children != undefined && item.children.length > 0,
      };
      if (item.children != undefined) {
        item.children.forEach((childItem) => {
          info.children.push(this.loopResourceData(childItem));
        });
      }
      return info;
    },
    //关闭弹窗
    getCheckedNodes() {
      this.treeshow = false;
      this.treeshow2 = false;
    },

    //添加权限方法
    async getCheckedKeys() {
      this.treeshow = false;
      let keylist = this.$refs.tree.getCheckedKeys(true); //获取取到的id值
      let biz_ids = keylist.join("|");
      if (keylist.length === 0) {
        biz_ids = "empty";
      }
      let res = await this.RequestPost("edit_item", {
        id: this.rows.id,
        business_type_ids: biz_ids,
      });
      // utils.showTip("筛源修改成功！");
      if (res.code === 0) {
        utils.showTip("筛源修改成功！");
      } else {
        utils.showSureModal({
          title: "删除提示",
          icon: require("../../assets/images/peach-svg/Frame 427318277 (1).svg"),
          modalContent: res.data,
        });
      }
    },
    resetChecked() {
      this.$refs.tree.setCheckedKeys([]);
    },
    //点击权限按钮弹窗
    async trees(row) {
      this.rows = row; //全局row信息
      this.treeshow = true;
      let res = await this.RequestPost("querySieveConfig_item", { id: row.id }); //api
      let menucheckList = []; //二级菜单数组
      let menucheckListids = []; //二级菜单ID数组
      if (res.code == 0) {
        if (res.data != null && res.data != null) {
          res.data.forEach((item) => {
            item.children.forEach((item2) => {
              menucheckList.push(item2);
            });
          });
        }
      }
      menucheckList.forEach((item) => {
        menucheckListids.push(item.business_type_id);
      });
      this.$refs.tree.setCheckedKeys(menucheckListids); //把已勾选的权限id显示
    },
    onSearchGetList() {
      this.searchData.page_index = 1;
      this.getList();
    },
    async getList() {
      utils.showLoading();
      let res = await this.RequestPost("query_list", this.searchData);
      if (res.code == 0 && res.data != null) {
        this.list = [];
        if (res.data.list != null) this.list = res.data.list;
        this.totalCnt = res.data.total;
      }
      await utils.sleepMs(500);
      utils.hideLoading();
    },
    //添加 编辑用户
    async editInfo(row, type) {
      this.eid = row.id;
      this.handleType = type;
      let title = "";
      let info = {};
      if (this.UserInfo.role == "管理员") {
        this.format.leader_id.labelHide = false;
      } else {
        this.format.leader_id.labelHide = true;
      }
      if (this.handleType == 1) {
        title = "添加用户";
        this.format.account.labelDisabled = false;
        this.format.passwd.labelDisabled = false;
        info = {
          account: "",
          passwd: "",
          role_id: "",
          leader_id: "",
          tag: "",
        };
        this.onSelectChange("role_id", info.role_id);
      } else if (this.handleType == 2) {
        this.format.account.labelDisabled = false;
        this.format.passwd.labelDisabled = false;
        title = "编辑用户";
        info = {
          id: row.id,
          account: row.account,
          role_id: row.role_id,
          leader_id: row.leader_id,
          tag: row.tag,
        };
        this.onSelectChange("role_id", info.role_id);
      } else if (this.handleType == 3) {
        this.format.account.labelDisabled = true;
        // this.format.passwd.labelDisabled = true
        title = "重置密码";
        info = {
          account: row.account,
          passwd: "8888888a",
        };
        this.handleType = 3;
      } else if (this.handleType == 6) {
        this.format.account.labelDisabled = true;
        // this.format.passwd.labelDisabled = true
        title = "更换筛号源";
        info = {
          sieve_source_config_id: "",
        };
        this.handleType = 6;
      } else if (this.handleType == 7) {
        title = "批量修改筛料源";
        let new_ids = "";
        if (
          (this.selectRows.checked == true &&
            this.selectRows.records.length >= 1) ||
          (this.selectRows.checked == false &&
            this.selectRows.records.length >= 1)
        ) {
          //导出值用id|id形式拼接
          this.selectRows.records.forEach((item) => {
            new_ids += "|" + item.id;
          });
          if (new_ids != "") {
            new_ids = new_ids.substring(1);
          }
        }
        info = {
          ids: new_ids,
          sieve_source_config_id: "",
        };
        this.handleType == 7;
      }
      this.info = info;
      this.formPopIndex = await utils.showFormPage(
        { title: title, el: this.$parent.$el, width: 700, cancelBtnStatus: 0 },
        this.info,
        this.format,
        this.ruleValidate,
        this.updateInfo,
        this.onSelectChange
      );
    },
    async updateInfo(info) {
      utils.showLoading();
      let code = -1;
      let actionName = "";
      let tipText = "";
      let postData = utils.cloneObj(info);
      if (this.handleType == 1) {
        actionName = "add_item";
        tipText = "添加成功！";
        postData.account = postData.account.replace(/\s+/g, "");
      } else if (this.handleType == 2) {
        actionName = "edit_item";
        tipText = "编辑成功！";
        postData["id"] = this.eid;
        postData["account"] = postData.account.replace(/\s+/g, "");
      } else if (this.handleType == -1) {
        actionName = "del_item";
        tipText = "删除成功！";
        postData = { id: postData.Id };
      } else if (this.handleType == 3) {
        actionName = "resetPasswd_item";
        tipText = "修改成功";
        postData = { id: this.eid, passwd: postData.passwd };
      } else if (this.handleType == 4) {
        actionName = "enable_item";
        tipText = "启用成功！";
        postData = { id: postData.id };
      } else if (this.handleType == 5) {
        actionName = "disable_item";
        tipText = "冻结成功！！";
        postData = { id: postData.id };
      } else if (this.handleType == 7) {
        actionName = "updateBatch_item";
        tipText = "筛源修改成功！";
      } else if (this.handleType === 8) {
        utils.hideFormPage(this.formPopIndex);
        utils.hideLoading();
        return;
      }
      if (
        this.handleType == 1 ||
        this.handleType == 2 ||
        this.handleType == -1
      ) {
        bus.$emit("update-recharge-account-list");
      }
      let res = await this.RequestPost(actionName, postData);
      code = res.code;
      if (code == 0) {
        utils.hideFormPage(this.formPopIndex);
        await utils.sleepMs(1000);
        utils.showTip(tipText);
      } else {
        utils.shadowModel({
          icon: require("../../assets/images/Frame 427318277.svg"),
          modalContent: res.data,
          title: "提交失败",
        });
      }

      utils.hideLoading();
      this.getList();
    },
    //导出
    async downloadFile() {
      // utils.showLoading("正在生成中")
      let new_ids = "";
      if (
        (this.selectRows.checked == true &&
          this.selectRows.records.length != 0) ||
        (this.selectRows.checked == false &&
          this.selectRows.records.length != 0)
      ) {
        //导出值用id|id形式拼接
        this.selectRows.records.forEach((item) => {
          new_ids += "|" + item.id;
        });
        if (new_ids != "") {
          new_ids = new_ids.substring(1);
        }
        let res = await this.RequestPost("export_list", { ids: new_ids });
        if (res.code == 0) {
          utils.hideLoading();
          await utils.sleepMs(500);
          window.location.href = ACDN + res.data;
        } else {
          utils.showSureModal({
            icon: require("../../assets/images/peach-svg/hongtan.svg"),
            modalContent: res.data,
            title: "提示",
          });
        }
      } else {
        utils.showSureModal({
          icon: require("../../assets/images/peach-svg/bluegth.svg"),
          modalContent: "请选择一项",
          title: "提示",
        });
      }
    },
    //删除
    sureDel(item, type) {
      this.handleType = -1;
      utils.showSureModal(
        {
          title: "删除提示",
          icon: require("../../assets/images/peach-svg/Frame 427318277 (1).svg"),
          modalContent: "确认删除 " + item.id + " ?",
          callBackArgs: { Id: item.id },
        },
        (res) => {
          let code = res.code;
          if (code == 0) {
            let data = res.data;
            this.updateInfo(data);
          }
        }
      );
    },
    onChangePageSize(page, pageSize) {
      this.modal = true;
      this.searchData.page_index = page;
      this.searchData.page_size = pageSize;
      this.getList();
    },
    changeDate() {
      this.searchData.start = Date.parse(this.searchDate[0]) / 1000;
      this.searchData.end = Date.parse(this.searchDate[1]) / 1000 + 86400;
      this.onSearchGetList();
    },
    initDate() {
      let nowDay = "";
      let beginDay = nowDay;
      let endDay = nowDay;
      this.searchDate = [new Date(beginDay), new Date(endDay)];
      this.changeDate();
    },
    async onSelectChange(label, value, reset) {
      this.format.leader_id.labelValue = [];
      if (label == "role_id" && value != "") {
        let res = await this.RequestPost("queryLeaders_list", {
          submit_type: 2,
          will_role_id: value,
        });
        //上级
        if (res.code == 0 && res.data != null) {
          res.data.forEach((item) => {
            this.format.leader_id.labelValue.push({
              id: item.id,
              name: item.account,
            });
          });
        }
      }
    },
    slotHeader(h) {
      return [
        h("div", {
          class: { allCount: true },
          style: { "margin-left": "10px" },
        }),
      ];
    },
    filterPartner(item) {
      if (item.Id == -1) return true;
      if (this.searchData.searchBusinessId == -1) return true;
      return item.BusinessId == this.searchData.searchBusinessId;
    },
  },
  mounted() {},
};
</script>
